﻿using System.Linq;
using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.ActiveCheckPoint, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_ActiveCheckPoint : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.ActiveCheckPoint;

        public override string name => LevelEditorConst.ActiveCheckPoint;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [InspectorName("是否激活指定标记点"), Tooltip("否为取消激活，一般不会正式使用")] public bool isToActive;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_ActiveCheckPoint()
            {
                isToActive = this.isToActive
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter
                ((x) => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_ActiveCheckPoint rNode)
            {
                this.isToActive = rNode.isToActive;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_ActiveCheckPoint rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid, nameof(tagOrMcid));
            }
        }
    }
}